from bs4 import BeautifulSoup
import requests

# step 1: send request to server
resp = requests.get("https://unsplash.com/")
resp.encoding = "utf-8"
# print(resp.text)

main_page = BeautifulSoup(resp.text, "html.parser")
print(main_page)
#
#
# # find something from page sources
# # find, find_all
#
p_index = 1

imgList = main_page.find_all("img")

print(imgList)
for img in imgList:
    print(img.get("src"))
    f = open("./pictures/{}.png".format(p_index), mode="wb")
    try:
        f.write(requests.get(img.get("src")).content)
        print("Download!")
    except Exception as e:
        print(e)
        continue
    p_index += 1
